package org.example.zsfmybatis.controller;

import org.apache.ibatis.annotations.Delete;
import org.example.zsfmybatis.mapper.UserMapper;
import org.example.zsfmybatis.model.User;
import org.example.zsfmybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("/register")
    public String register(@RequestBody User user) {
        int u;
        u=userService.add(user);
        if (u==1)
            return "success";
        else
            return "fail";
    }
    @GetMapping("/findById/{id}")
    public User findById(@PathVariable String id) {
        User u=userService.getUser(id);
        return u;
    }
    @PatchMapping("/update")
    public void update(@RequestBody User user) {
        userService.update(user);
    }
    @DeleteMapping("/delete")
    public void delete(@RequestBody User user) {
        userService.delete(user);
    }
    @PostMapping("order")
    public void order(String meals_id,String user_id,int sum) {
        userService.order(meals_id,user_id,sum);
    }
}
